package zhengzei;

import org.junit.Test;

/*
   正则基础
 */
public class JiChu {

    public static void main(String[] args) {
        /*
            .  任何字符
            d 	数字：[0-9]
            D   非数字： [^0-9]
            \s 	空白字符：[ \t\n\x0B\f\r]
            \S 	非空白字符：[^\s]
            \w 	单词字符：[a-zA-Z_0-9]
            \W 	非单词字符：[^\w]
        */
        System.out.println("a".matches(".")); //true
        System.out.println("1".matches("\\d")); //true
        System.out.println("%".matches("\\D")); //true
        System.out.println("\r".matches("\\s")); //true
        System.out.println("^".matches("\\S")); //true
        System.out.println("a".matches("\\w")); //true

        /*
            Greedy 数量词
            X?	X，一次或一次也没有
            X*	X，零次或多次
            X+	X，一次或多次
            X{n}	X，恰好n次
            X{n,}	X，至少n次
            X{n,m}	X，至少n次，但是不超过m次
        */
        System.out.println("--------------------------");
        System.out.println( "a".matches(".") );
        System.out.println( "a".matches("a") );
        System.out.println("a".matches("a?") );
        System.out.println( "aaa".matches("a*") );
        System.out.println( "".matches("a+") );
        System.out.println( "aaaaa".matches("a{5}") );
        System.out.println( "aaaaaaaaa".matches("a{5,8}") );
        System.out.println( "aaa".matches("a{5,}") );
        System.out.println( "aaaaab".matches("a{5,}") );

        /*
            范围表示
            [abc]	a、b 或 c（简单类）
            [^abc]	任何字符，除了 a、b 或 c（否定）
            [a-zA-Z]	a 到 z 或 A 到 Z，两头的字母包括在内（范围）
        */
        System.out.println("--------------------------");
        System.out.println( "a".matches("[a]") );
        System.out.println( "aa".matches("[a]+") );
        System.out.println( "abc".matches("[abc]{3,}") );
        System.out.println( "abc".matches("[abc]+") );
        System.out.println( "dshfshfu1".matches("[^abc]+") );
        System.out.println( "abcdsaA".matches("[a-z]{5,}") );
        System.out.println( "abcdsaA12".matches("[a-zA-Z]{5,}") );
        System.out.println( "abcdsaA12".matches("[a-zA-Z0-9]{5,}") );
    }

    @Test
    public void show01(){
        boolean matches = "aaaa".matches("[^\\u4e00-\\u9fa5]+"); //^:取反 +:至少一个
        System.out.println(matches);

    }

    @Test
    public void show02(){
        // ^(((B|b)(U|u)(L|l)(L|l)(E|e)(T|t)(S|s)).)*$
        boolean matches = "hamster.hay.treat".matches("^(((H|h)(A|a)(M|m)(S|s)(T|t)(E|e)(R|r)(S|s)*(\\s|-|'|\\.)*(H|h)(A|a)(Y|y)(\\s|-|'|\\.)*(T|t)(R|r)(E|e)(A|a)(T|t)).)*$");
        System.out.println(matches);



        String s = "^((?!(H|h)(A|a)(M|m)(S|s)(T|t)(E|e)(R|r)(S|s)*(\\s|-|''|\\.)*(H|h)(A|a)(Y|y)(\\s|-|''|\\.)*(T|t)(R|r)(E|e)(A|a)(T|t)).)*$";

    }

    @Test
    public void show03(){
        boolean matches = "Washington, DC".matches("^(?i)(?:Alabama|Alaska|Arizona|Arkansas|California|Colorado|Connecticut|Delaware|Washington,? ?DC|Florida|Georgia|Hawaii|Idaho|Illinois|Indiana|Iowa|Kansas|Kentucky|Louisiana|Maine|Maryland|Massachusetts|Michigan|Minnesota|Mississippi|Missouri|Montana|Nebraska|Nevada|New ?Hampshire|New ?Jersey|New ?Mexico|New ?York|North ?Carolina|North ?Dakota|Ohio|Oklahoma|Oregon|Pennsylvania|Rhode ?Island|South ?Carolina|South ?Dakota|Tennessee|Texas|Utah|Vermont|Virginia|Washington|West ?Virginia|Wisconsin|Wyoming|American ?Samoa|Federated ?States ?of ?Micronesia|Guam|Marshall ?Islands|Northern ?Mariana ?Islands|Palau|Puerto ?Rico|Virgin ?Islands)$");
        System.out.println(matches);
    }

}
